package com.agua.enturno.vista.dto;

import com.agua.enturno.modelo.roles.Rol;
import org.joda.time.DateTime;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class UsuarioDeSessionDTO implements Serializable {

	private static final long serialVersionUID = 1L;

	private Long id;
	private String nombreCompleto;
	private String email;
	private DateTime ultimoLogueo;
	
	private Map<String, Long> rolesAndIds = new HashMap<String, Long>();
	
	
	/*------------------------------------ Constructors ------------------------------------*/

	public UsuarioDeSessionDTO(Long id, String nombreCompleto, String email, DateTime ultimoLogueo, Set<Rol> roles) {
		super();
		this.id = id;
		this.nombreCompleto = nombreCompleto;
		this.email = email;
		this.ultimoLogueo = ultimoLogueo;
		this.generateRolesAndIds(roles);
	}

	/*--------------------------------------------------------------------------------------*/
	/*---------------------------------- Geters and seters ---------------------------------*/

	public Long getId() {
		return id;
	}

	public String getNombreCompleto() {
		return nombreCompleto;
	}

	public String getEmail() {
		return email;
	}
	
	public DateTime getUltimoLogueo() {
		return ultimoLogueo;
	}
	
	public Map<String, Long> getRolesAndIds() {
		return rolesAndIds;
	}
	
	public Set<String> getRoles() {
		return rolesAndIds.keySet();
	}
	
	public Long getId(String rol) {
		return rolesAndIds.get(rol);
	}
	
	/*--------------------------------------------------------------------------------------*/
	/*----------------------------------- Private methods ----------------------------------*/

	private void generateRolesAndIds(Set<Rol> roles) {
		
		for (Rol rol : roles) 
			this.rolesAndIds.put(rol.getNombreDeRol(), rol.getId());
	}

	/*--------------------------------------------------------------------------------------*/
	
}
